/*
 *
 *  * Copyright (c) 2016. For Intelligent Group.
 *
 */
package com.intelligent.ispc.client.test.fixtable;

import com.intelligent.ispc.client.ex.dynamictable.DyTableModel;

import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * Created by Ethan.Yang on 16/10/21.
 */
public class MyDyTableModel extends AbstractTableModel implements DyTableModel<TestDto> {
    private String[] columns;
    private List<TestDto> data;

    public MyDyTableModel(String[] columns) {
        this.columns = columns;
    }

    @Override
    public int getRowCount() {
        return data.size();

    }

    @Override
    public int getColumnCount() {
        return columns.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        TestDto dto = data.get(columnIndex);
        switch (rowIndex) {
            case 0:
                return dto.getId();
            case 1:
                return dto.getName();
            default:
                return "" + rowIndex;
        }
    }

    public void setData(List<TestDto> data) {
        this.data = data;
//        fireTableDataChanged();
    }

    @Override
    public List getData() {
        return data;
    }
}
